<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>欢迎查看你的队伍</title>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/script/common.js" common-data-1="{:U('Mix/dest')}"></script>
  <link rel="stylesheet" href="__PUBLIC__/script/jquery-weui/dist/lib/weui.min.css">
  <link rel="stylesheet" href="__PUBLIC__/script/jquery-weui/dist/css/jquery-weui.min.css">
  <link rel="stylesheet" href="__PUBLIC__/styles/base.css">
  <link rel="stylesheet" href="__PUBLIC__/styles/my_pingu.css">
  <link rel="stylesheet" href="__PUBLIC__/styles/font/iconfont.css">
</head>
<body>
  <!-- 欢迎 -->
  <div class="hidden">
    <input type="hidden" name='申请按钮不需要申请时填写' id='formAlreadyHad' value='test'>
    <!-- 不要管下边这一行的表单 -->
    <form autocomplete="off" action method="post" id ='hidden_form'></form>
  </div>
  <div class="container">
    <div class="header">{$Think.session.user.p_u_id|get_web_f_mesage}</div>
    <div class="nav">
      <div class="left" inori-href="{:U('Wchat/main')}" id='my_tuandui'>我的团队</div>
      <div class="center active" id='my_pinggu'>我的评估</div>
      <if condition='$Think.session.user.web_type eq 1' ><div id='nav_my_tuandui' class="right" inori-href="{:U('Mix/show_chat_list_team')}">团队咨询</div></if>
    </div>
    <div class="weui-search-bar" id="searchBar">
      <form autocomplete="off" class="weui-search-bar__form" id='search_for' method="get" action="{:U('Mix/show_chat_list')}">
        <div class="weui-search-bar__box">
          <i class="weui-icon-search"></i>
          <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="输入客户姓名、手机号" name='search_kehu_name' required>
          <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
        </div>
        <label class="weui-search-bar__label" id="searchText">
          <i class="weui-icon-search"></i>
          <span>客户姓名、手机号</span>
        </label>
      </form>
      <a href="javascript:;" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
    </div>

    <div class="roomList">
      <!-- 一个聊天室一个roomItem -->
      <!-- roomItem 的inori-href指示跳转目标，不要写a链接了 -->
      <!-- &nbsp; 不能删除，用来占位防止潜在的错位，有些地方我觉得数据是一定存在的所以就不放 -->
      <volist name='apply' id='vo'>
        <div class="roomItem" inori-href='{:U('WebUser/last_product')}?search_data={$vo.search_data}&chat_id={$vo.chat_id}&c_id={$vo.c_id}'>
          <div class="vip_info">
            <div class="vip_name">
              &nbsp;{$vo.kehu_name}
            </div>
            <div class="vip_type">
              &nbsp;{$vo.kehu_old}岁
            </div>
          </div>
          <div class="vip_pro" style="opacity: 0;">
            <div class="vip_pro_qudao">
              &nbsp;{$vo.first_user}
            </div>
            <div class="vip_pro_type">
              &nbsp;{$vo.first_user}
            </div>
          </div>
          <div class="room_init_time">
            {$vo.time}
          </div>
          <div class="i_want_this" inori-href='./web_user_shenqing.html' inori-data-id='{$vo.cd_id}' inori-data='{$vo.apply_data}'>
            <if condition='$vo.apply_data eq null'>
            <div class="btn_form">正式申请</div>
            </if>
          </div>
          <div class="more">
            <i class="iconfont">&#xe6a7;</i>
          </div>
        </div>
      </volist>
    </div>
    <div id='back_all'
      style='text-align: center;font-size: 13px;padding: 15px;text-decoration: underline;color: #757575;'
      inori-href="{:U('Mix/show_chat_list')}">点击查看全部
    </div>
  </div>
  <script src="__PUBLIC__/script/jquery-weui/dist/js/jquery-weui.min.js"></script>

  <!-- 跳转 -->
  <script>
    $(document).ready(() => {
      sessionStorage.setItem('kehu_old', '')
      $('#my_tuandui').on('click', (evt) => {
        location.href = `${$(evt.target).attr('inori-href')}?font_end_not_submit=${Math.random()}`
      })
      // $('#my_pinggu').on('click', (evt) => {
      //   location.href = `${$(evt.target).attr('inori-href')}?font_end_not_submit=${Math.random()}`
      // })
      $('#nav_my_tuandui').on('click', (evt) => {
        location.href = `${$(evt.target).attr('inori-href')}?font_end_not_submit=${Math.random()}`
      })
      if (/\?search_kehu_name\=/.test(location.href)) {
        $('#back_all').on('click', (evt) => {
          location.href = `${$(evt.target).attr('inori-href')}?font_end_not_submit=${Math.random()}`
        })
      } else {
        $('#back_all').remove()
      }
      // 跳转聊天室
      $(`.roomItem`).each((index, item) => {
        // 每个链接只能点一次
        $(item).one('click', (evt) => {
          const thisRoomItem = $(evt.target).closest(`.roomItem`)
          evt.stopPropagation()
          evt.preventDefault()
          if(String(thisRoomItem.attr('inori-data')) === '') {
            $.toptip(`该次搜索条件不完整，不予跳转`, 'error')
            throw new Error(`该次搜索条件不完整，不予跳转`)
          }
          if(String(thisRoomItem.attr('inori-href')) !== 'null') {
            thisRoomItem.one('click', () => {
              $.toptip(`正在准备数据，请稍后。。。`, 'success')
            })
            thisRoomItem.one('click', () => {
              location.reload()
            })
            location.href = `${thisRoomItem.attr('inori-href')}`
          } else {
            $.toptip(`聊天室链接不存在！请联系相关审核员或者管理员`)
            thisRoomItem.on('click', () => {
              $.toptip(`聊天室链接不存在！请联系相关审核员或者管理员`)
            })
          }
        })
      })
      // 跳转表单填写
      $(`.i_want_this`).each((index, item) => {
        $(item).one('click', (evt) => {
          evt.stopPropagation()
          const thisFormLine = $(evt.target).closest(`.i_want_this`)
          const formURL = String(thisFormLine.attr(`inori-href`))
          if (formURL === 'null') {
            /** 废分支 **/
              const jumpURL = String($('#formAlreadyHad').val())
              const toptip = `正在跳转至指定申请页面，请稍后。。。`
              // 不需要填写
              $.toptip(toptip, 'success')
              // 去除聊天室跳转
              $(`.roomItem`).each((index, item) => {$(item).off('click')})
              thisFormLine.on('click', {
                toptip: toptip
              }, (evt) => {
                evt.stopPropagation()
                $.toptip(evt.data.toptip, 'success')
              })
              // location.href = `${jumpURL}?front_end_not_submit=${Math.random()}`
            /** end 废分支 **/
          } else {
            // 需要填写
            const toptip = `正在跳转至指定客户资料填写页面，请稍后。。。`
            const cdID = thisFormLine.attr(`inori-data-id`)
            $.toptip(toptip, 'success')
            // 去除聊天室跳转
            $(`.roomItem`).each((index, item) => {$(item).off('click')})
            thisFormLine.on('click', {
              toptip: toptip
            }, (evt) => {
              evt.stopPropagation()
              $.toptip(evt.data.toptip, 'success')
            })
            location.href = `${formURL}?cd_id=${cdID}`
            // location.href = `${formURL}?front_end_not_submit=${Math.random()}`
          }
        })
      })
      // 处理日期
      $('.room_init_time').each((index, item) => {
        const realTime = $(item).text().match(/(\d\d\d\d)年(\d\d)月(\d\d)日/)
        if (realTime === null || !realTime.length || realTime.length < 4) {
          console.log(`发现一个不规则的时间展示: ${realTime}`)
        } else {
          $(item).text(`${realTime[1]}/${realTime[2]}/${realTime[3]}`)
        }
      })
    })
  </script>
</body>
</html>